Array.prototype.selfMap = function () {
  const ary = this;
  const result = [];
  const [fn, thisArg] = [].slice.call(arguments);
  if (typeof fn !== "function") {
    throw new TypeError(fn + "is not a function");
  }
  for (let i = 0; i < ary.length; i++) {
    result.push(fn.call(thisArg, ary[i], i, ary));
  }
  return result;
};
const a = new Array(1, 2, 3, 4);
console.log(
  a.selfMap((item) => {
    console.log(item);
    return item + "1";
  })
);

// 方法二
Array.prototype.fakeMap = function (fn, context) {
  let arr = this;
  let temp = [];
  for (let i = 0; i < arr.length; i++) {
    let result = fn.call(context, arr[i], i, arr);
    temp.push(result);
  }
  return temp;
};
const res = [1, 2, 3].fakeMap((item) => {
  console.log(item);
  return item + "2";
});
console.log(res);

const fns = () => {
  const [fn, thisArg] = [].slice.call(arguments);
  console.log(arguments, fn, thisArg, 'fn');
}

// Array.prototype.rewMap = () => {
//   // 要被返回的新数组
//   const result = []
//   const arr = this
//   const 
// }
